% fname: routing_xy__topology_8x8__.m
% ./noxim -routing xy -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 2 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_xy__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        20.8396      0.0130932            114            773           6180
           0.0015        20.9623      0.0123625            109            742           5934
           0.0015        20.0285      0.0126455            145            771           6171
           0.0015         20.622      0.0128599             89            746           5967
           0.0015        21.8835      0.0141773            129            781           6238
           0.0015         21.095      0.0139085            113            779           6231
           0.0015        24.4676      0.0130847            206            772           6176
           0.0015        22.1898      0.0130979            170            785           6287
           0.0015        24.8812      0.0129652            192            791           6327
           0.0015        21.3992       0.013096            129            734           5867
           0.0015        22.6692      0.0125337            102            789           6317
           0.0015        20.1883      0.0121066             97            738           5908
           0.0015        21.9714      0.0131701            149            803           6427
           0.0015        21.0408      0.0124611             85            760           6081
           0.0015        23.6316      0.0122742            178            760           6088
           0.0015        22.0764      0.0130958            114            785           6286
           0.0015        22.0024      0.0138458            158            830           6646
           0.0015        21.5835      0.0129583            134            778           6220
           0.0015        21.5447       0.012319            121            716           5716
           0.0015        22.7941      0.0135875            138            816           6522
           0.0017        22.2111       0.014036             95            829           6625
           0.0017        25.8904      0.0146516            194            894           7150
           0.0017        24.6369      0.0140337            134            884           7073
           0.0017         24.895      0.0145833            194            876           7000
           0.0017        21.2111      0.0135717            111            829           6623
           0.0017        25.7638      0.0153686            162            906           7254
           0.0017        26.7302      0.0156377            138            923           7381
           0.0017        22.1619          0.014            109            840           6720
           0.0017        23.7573      0.0140754            148            886           7094
           0.0017        25.0237      0.0136028            150            844           6747
           0.0017          22.61      0.0146292            107            877           7022
           0.0017        22.7714      0.0136127            138            831           6643
           0.0017        25.0624      0.0138937            200            834           6669
           0.0017          22.38      0.0146466            107            850           6796
           0.0017        24.9436      0.0142063            177            851           6819
           0.0017        25.2145         0.0147            162            881           7056
           0.0017        23.5018      0.0138709            172            847           6769
           0.0017        23.5516      0.0142021            189            852           6817
           0.0017        25.9823      0.0143602            237            847           6778
           0.0017        24.7946      0.0142944            156            886           7090
           0.0019        25.5977      0.0158644            142            937           7488
           0.0019        25.7313      0.0164098            144           1001           8008
           0.0019         35.212      0.0175625            308           1019           8149
           0.0019        34.2215      0.0174037            255           1061           8493
           0.0019         25.565      0.0155208            152            931           7450
           0.0019        32.6745      0.0164698            297           1020           8169
           0.0019        26.0797      0.0158024            182            979           7838
           0.0019        26.0846       0.015575            190            934           7476
           0.0019        25.8948      0.0157987            219            932           7457
           0.0019         25.981      0.0154816            296            945           7555
           0.0019        25.2661      0.0158468            176            981           7860
           0.0019        28.1942      0.0159563            222            958           7659
           0.0019        28.0153      0.0160861            221            981           7850
           0.0019        25.4815      0.0159385            178            972           7778
           0.0019         29.503      0.0162319            295           1006           8051
           0.0019        27.0095      0.0152903            135            947           7584
           0.0019        32.2196      0.0167585            245            988           7910
           0.0019        24.4098      0.0162646            162            976           7807
           0.0019        29.6963      0.0159879            278            991           7930
           0.0019        22.6731          0.015            162            930           7440
           0.0021        30.7273      0.0171598            241           1045           8374
           0.0021        29.1041      0.0162109            290           1037           8300
           0.0021         30.934      0.0168066            219           1076           8605
           0.0021        30.9728      0.0165827            337           1028           8225
           0.0021        33.6629      0.0180678            303           1065           8528
           0.0021        29.5806      0.0167381            182           1054           8436
           0.0021        37.5375      0.0173393            512           1092           8739
           0.0021        32.5405      0.0174722            253           1099           8806
           0.0021        28.3659       0.016752            159           1055           8443
           0.0021        30.2949      0.0170533            373           1041           8322
           0.0021        43.8957      0.0176816            541           1131           9053
           0.0021        28.4448      0.0170927            286           1059           8478
           0.0021        28.9045      0.0174052            241           1078           8633
           0.0021        28.1832      0.0167227            257           1070           8562
           0.0021        29.8341       0.017123            226           1061           8493
           0.0021        28.0642      0.0178175            212           1122           8980
           0.0021        42.5693      0.0172817            479           1089           8710
           0.0021        30.8608      0.0165383            258           1027           8203
           0.0021        28.6973      0.0174333            235           1044           8368
           0.0021        30.0804      0.0170801            252           1094           8745
           0.0023        39.5507      0.0185746            708           1153           9213
           0.0023        38.9243      0.0192309            487           1136           9077
           0.0023        34.1556      0.0185471            313           1131           9051
           0.0023        51.0099      0.0191687            471           1208           9661
           0.0023        47.3966      0.0195655            767           1233           9861
           0.0023        50.4128      0.0185734            516           1170           9361
           0.0023        43.7034      0.0190098            279           1217           9733
           0.0023        39.6216      0.0189375            398           1213           9696
           0.0023         38.824      0.0198238            460           1210           9674
           0.0023         45.973      0.0194067            491           1222           9781
           0.0023        32.7617      0.0189435            400           1175           9396
           0.0023        42.2041      0.0184629            423           1181           9453
           0.0023        35.3044      0.0183711            255           1176           9406
           0.0023        44.1044      0.0194375            412           1245           9952
           0.0023        46.8264      0.0194395            560           1204           9642
           0.0023        34.1444      0.0175254            326           1122           8973
           0.0023        30.9029      0.0181875            217           1164           9312
           0.0023        52.7657      0.0195266            652           1191           9529
           0.0023        32.5974       0.018623            269           1155           9237
           0.0023        44.3668      0.0192718            280           1216           9713
           0.0025        54.4726      0.0211766            478           1333          10673
           0.0025        68.5156       0.020371            873           1282          10267
           0.0025        71.2259      0.0199512            918           1275          10215
           0.0025        39.6051      0.0194758            289           1208           9660
           0.0025        45.4363      0.0193075            337           1217           9731
           0.0025        56.4323      0.0204199            493           1307          10455
           0.0025        59.0849      0.0201964            776           1272          10179
           0.0025        49.0223      0.0202702            538           1256          10054
           0.0025        51.6196      0.0195859            654           1254          10028
           0.0025         74.157      0.0206492            840           1280          10242
           0.0025        63.0857      0.0209425            914           1319          10555
           0.0025        49.3673      0.0205867            457           1277          10211
           0.0025        52.7504      0.0197637            626           1266          10119
           0.0025        82.6389      0.0206367            923           1321          10566
           0.0025        51.0351      0.0202359            745           1254          10037
           0.0025        44.9028      0.0195714            797           1234           9864
           0.0025        51.6744      0.0202379            704           1256          10038
           0.0025        58.0511      0.0195762            633           1253          10023
           0.0025        65.2246      0.0202012            597           1291          10343
           0.0025        45.2986      0.0204274            473           1266          10132
           0.0027        87.0954      0.0217812           1080           1394          11152
           0.0027        57.7952       0.021494            504           1333          10661
           0.0027        96.9709      0.0220449           1169           1410          11287
           0.0027        71.0189      0.0215449            806           1379          11031
           0.0027        133.313      0.0213066           1811           1363          10909
           0.0027        124.206      0.0226351           1330           1404          11227
           0.0027        105.448      0.0221448           1145           1396          11161
           0.0027        108.375          0.022           1013           1385          11088
           0.0027         198.91      0.0217103           2175           1368          10942
           0.0027         68.506       0.021006           1086           1324          10587
           0.0027        183.398      0.0226409           2345           1428          11411
           0.0027        75.6652      0.0214187            786           1350          10795
           0.0027        72.2818      0.0213512           1182           1345          10761
           0.0027        143.484      0.0216607           2549           1365          10917
           0.0027        75.2672      0.0211331            972           1310          10482
           0.0027        152.383      0.0218829           1577           1380          11029
           0.0027        189.223      0.0216211           2405           1384          11070
           0.0027        100.271      0.0218911           1030           1357          10858
           0.0027        106.315      0.0225847           1041           1399          11202
           0.0027        347.403      0.0228262           5156           1462          11687
           0.0029         321.91      0.0224727           5711           1438          11506
           0.0029        250.022      0.0221387           4635           1418          11335
           0.0029         170.52       0.022246           1613           1379          11034
           0.0029        266.695       0.023506           2970           1481          11847
           0.0029          290.1      0.0223535           3248           1432          11445
           0.0029        172.842      0.0229707           3669           1471          11761
           0.0029        222.022      0.0228214           3047           1437          11502
           0.0029        123.343      0.0224785           1427           1439          11509
           0.0029        344.359      0.0225801           4590           1444          11561
           0.0029        257.753      0.0229883           3577           1470          11770
           0.0029        128.753      0.0230933           1191           1455          11639
           0.0029        368.395      0.0222044           6327           1399          11191
           0.0029        406.794      0.0230333           5096           1381          11056
           0.0029        163.228      0.0227664           2055           1390          11110
           0.0029        265.469      0.0225556           3358           1420          11368
           0.0029        239.815      0.0227996           3355           1437          11491
           0.0029         290.52       0.022666           4859           1450          11605
           0.0029         184.21       0.023041           1938           1475          11797
           0.0029        97.3898      0.0217637           1298           1393          11143
           0.0029        325.523      0.0219133           2998           1357          10869
           0.0031        554.348      0.0234921           6120           1479          11840
           0.0031         422.33      0.0227031           3682           1453          11624
           0.0031        465.186      0.0230893           5801           1455          11637
           0.0031         557.49      0.0230496           6381           1451          11617
           0.0031        524.162      0.0221035           5913           1416          11317
           0.0031        381.389      0.0232129           4603           1485          11885
           0.0031        384.012       0.022582           7812           1446          11562
           0.0031        323.372      0.0226607           5828           1428          11421
           0.0031        416.459      0.0235859           6153           1510          12076
           0.0031         354.41      0.0237579           4253           1496          11974
           0.0031        469.916      0.0230645           5310           1476          11809
           0.0031         351.41      0.0232344           4378           1487          11896
           0.0031        403.391      0.0228945           4836           1464          11722
           0.0031        353.725      0.0218945           4031           1402          11210
           0.0031        412.528      0.0228906           4082           1467          11720
           0.0031        371.985      0.0232891           5532           1488          11924
           0.0031         456.27      0.0236905           7491           1492          11940
           0.0031        536.388      0.0233591           5247           1472          11773
           0.0031        471.354       0.022625           7258           1425          11403
           0.0031        364.078      0.0229238           5608           1468          11737
           0.0033        459.945      0.0231953           7159           1484          11876
           0.0033        503.369      0.0232619           5487           1465          11724
           0.0033        660.776      0.0234609           7284           1502          12012
           0.0033        624.894      0.0233591           7066           1473          11773
           0.0033        660.707      0.0227363           6267           1455          11641
           0.0033        443.647       0.023668           5996           1516          12118
           0.0033        400.473      0.0226504           6219           1449          11597
           0.0033        657.803      0.0232773           6684           1489          11918
           0.0033        494.751      0.0235625           5097           1509          12064
           0.0033        564.031       0.024496           5700           1519          12150
           0.0033         556.91      0.0238869           5816           1506          12039
           0.0033          444.7      0.0231445           5310           1482          11850
           0.0033        536.573      0.0236719           5756           1514          12120
           0.0033        587.076      0.0232778           6019           1468          11732
           0.0033        574.174      0.0235938           7248           1509          12080
           0.0033        475.844      0.0233591           6411           1471          11773
           0.0033        454.772      0.0236349           5852           1490          11912
           0.0033        488.956      0.0231445           6064           1479          11850
           0.0033        538.735      0.0232637           6568           1489          11911
           0.0033        418.619      0.0232109           6714           1488          11884
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
